using System;
using System.Collections.Generic;
using System.ComponentModel.Design;

public class Order : IComparable<Order>
{
    public int id { get; set; }
    public string customer { get; set; }
    public string name { get; set; }
    public int moneys { get; set; }
    public Order(int id, int moneys, string customer, string name)
    {
        this.customer = customer;
        this.id = id;
        this.moneys = moneys;
        this.name = name;
    }
    public int CompareTo(Order other)
    {
        return this.id - other.id;
    }
    public void show()
    {
        Console.WriteLine("Order id:{0},customer:{1},name:{2},moneys:{3}", id, customer, name, moneys);
    }
}

public class OrderService
{
    List<Order> orders = new List<Order>();
    public void AddOrder(Order order)
    {
        if (orders.Find(o => o.id == order.id) == null)
            orders.Add(order);
        else Console.WriteLine("Order already exists");
    }
    public void DeleteOrder(int id)
    {
        Order order = orders.Find(o => o.id == id);
        if (order != null)
        {
            orders.Remove(order);
        }
        else
        {
            Console.WriteLine("Order not found");
        }
    }
    public Order GetOrderId(int id)
    {
        Order order = orders.Find(o => o.id == id);
        if (order != null) return order;
        else Console.WriteLine("Order not found");
        return null;
    }
    public List<Order> GetOrderName(string name)
    {
        var nameOrders =
            from order in orders
            where order.name == name
            orderby order.moneys
            select order;
        List<Order> l=nameOrders.ToList();
        return l;
    }
    public List<Order> GetOrderCustomer(string customer)
    {
        var customerOrders =
            from order in orders
            where order.customer == customer
            orderby order.moneys
            select order;
        List<Order> l = customerOrders.ToList();
        return l;
    }
    public List<Order> GetOrderMoneys(int moneys)
    {
        var moneysOrders =
            from order in orders
            where order.moneys == moneys
            orderby order.id
            select order;
        List<Order> l = moneysOrders.ToList();
        return l;
    }
    public void UpdateOrder(int id, string customer, string name, int moneys)
    {
        Order order = orders.Find(o => o.id == id);
        if (order != null)
        {
            order.customer = customer;
            order.name = name;
            order.moneys = moneys;
        }
        else Console.WriteLine("Order not found");
    }
    public void sortOrders()
    {
        orders.Sort();
    }

}
public class d1
{
    public static void Main(string[] args)
    {
        OrderService orderService = new OrderService();

        while (true)
        {
            Console.WriteLine("1.Add Order");
            Console.WriteLine("2.Delete Order");
            Console.WriteLine("3.Get Order");
            Console.WriteLine("4.Update Order");
            Console.WriteLine("5.Sort Orders");
            Console.WriteLine("6.Exit");
            Console.Write("Enter your choice:");
            string choice = Console.ReadLine();
            switch (choice)
            {
                case "1"://add order
                    {
                        Console.Clear();
                        Console.WriteLine("Enter id:");
                        int id1 = int.Parse(Console.ReadLine());
                        Console.WriteLine("Enter customer:");
                        string customer1 = Console.ReadLine();
                        Console.WriteLine("Enter name:");
                        string name1 = Console.ReadLine();
                        Console.WriteLine("Enter moneys:");
                        int moneys1 = int.Parse(Console.ReadLine());
                        Order order1 = new Order(id1, moneys1, customer1, name1);
                        orderService.AddOrder(order1);
                        break;
                    }
                    
                case "2"://delete order
                    Console.Clear();
                    Console.WriteLine("Enter id:");
                    int id2 = int.Parse(Console.ReadLine());
                    orderService.DeleteOrder(id2);
                    break;
                case "3"://get order
                    Console.Clear();
                    Console.WriteLine("Get Order by what?");
                    Console.WriteLine("1.id");
                    Console.WriteLine("2.customer");
                    Console.WriteLine("3.name");
                    Console.WriteLine("4.moneys");
                    Console.Write("Enter your choice:");
                    string cmd = Console.ReadLine();
                    Console.Clear();
                    switch (cmd)
                    {//order by id,customer,name,moneys
                        case "1":
                            Console.WriteLine("Enter id:");
                            int id3 = int.Parse(Console.ReadLine());
                            Order order = orderService.GetOrderId(id3);
                            if (order != null) order.show();
                            break;
                        case "2":
                            Console.WriteLine("Enter customer:");
                            string customer3 = Console.ReadLine();
                            List<Order> orders = orderService.GetOrderCustomer(customer3);
                            if (orders != null)
                                foreach (var order2 in orderService.GetOrderCustomer(customer3))
                                {
                                    order2.show();
                                }
                            else Console.WriteLine("Order not found");
                            break;
                        case "3":
                            Console.WriteLine("Enter name:");
                            string name3 = Console.ReadLine();
                            List<Order> orders2 = orderService.GetOrderName(name3);
                            if (orders2 != null)
                                foreach (var order3 in orderService.GetOrderName(name3))
                                {
                                    order3.show();
                                }
                            else Console.WriteLine("Order nod found");
                            break;
                        case "4":
                            Console.WriteLine("Enter moneys:");
                            int moneys3 = int.Parse(Console.ReadLine());
                            List<Order> orders3 = orderService.GetOrderMoneys(moneys3);
                            if (orders3 != null)
                                foreach (var order4 in orderService.GetOrderMoneys(moneys3))
                                {
                                    order4.show();
                                }
                            else Console.WriteLine("Order nod found");
                            break;
                            
                    }
                    break;
                case "4"://update order
                    Console.WriteLine("Enter id:");
                    int id4 = int.Parse(Console.ReadLine());
                    Console.WriteLine("Enter customer:");
                    string customer4 = Console.ReadLine();
                    Console.WriteLine("Enter name:");
                    string name4 = Console.ReadLine();
                    Console.WriteLine("Enter moneys:");
                    int moneys4 = int.Parse(Console.ReadLine());
                    orderService.UpdateOrder(id4, customer4, name4, moneys4);
                    break;
                case "5"://sort orders
                    orderService.sortOrders();
                    break;
                case "6"://exit
                    return;
                default:
                    break;
            }
        }
    }
}